﻿Imports ACompany.OrderProcessing.Model
Imports NUnit.Framework

<TestFixture()> _
Public Class ProductTests

    <Test()> _
    Public Sub A_Product_Has_A_Broken_Business_Rule_If_Stock_Is_A_Negative_Figure()

        Dim aProduct As New Product
        aProduct.Name = "Hat"
        aProduct.Price = 33.99
        aProduct.Stock = -9

        Assert.IsTrue(ContainsBrokenRules("Stock cannot be a negative number", aProduct.GetBrokenRules))
    End Sub

    <Test()> _
   Public Sub A_Product_Has_A_Broken_Business_Rule_If_Its_Name_Is_Over_50_Chars()

        Dim aProduct As New Product
        aProduct.Name = "Hatsfgdfgdfgdfgdfgdfgdgdfgdfgdfgdfgdfgdfdggdfggfgdfggfddfgdfg"
        aProduct.Price = 33.99
        aProduct.Stock = 9

        Assert.IsTrue(ContainsBrokenRules("Name should be 50 chars or less", aProduct.GetBrokenRules))
    End Sub

    <Test()> _
    Public Sub A_Product_Has_A_Broken_Business_Rule_If_It_Has_No_Name()

        Dim aProduct As New Product
        aProduct.Price = 33.99
        aProduct.Stock = 9

        Assert.IsTrue(ContainsBrokenRules("Name is a required value", aProduct.GetBrokenRules))
    End Sub

    <Test()> _
    Public Sub A_Product_Has_A_Broken_Business_Rule_If_Its_Price_Is_A_Negative_Figure()

        Dim aProduct As New Product
        aProduct.Name = "Hat"
        aProduct.Price = -33.99
        aProduct.Stock = 1

        Assert.IsTrue(ContainsBrokenRules("Price cannot be a negative number", aProduct.GetBrokenRules))
    End Sub

    <Test()> _
   Public Sub A_Product_Is_Valid_If_It_Has_A_Price_Name_And_Stock()

        Dim aProduct As New Product
        aProduct.Name = "Hat"
        aProduct.Price = 33.99
        aProduct.Stock = 1

        Assert.AreEqual(0, aProduct.GetBrokenRules.Count)
    End Sub

    Private Function ContainsBrokenRules(ByVal ExpectedBrokeRule As String, ByVal ListOFBrokenRules As IList(Of Infrastructure.BrokenRule)) As Boolean

        For Each brokenRule As Infrastructure.BrokenRule In ListOFBrokenRules
            If ExpectedBrokeRule = brokenRule.Rule Then
                Return True
            End If
        Next

        Return False

    End Function

End Class
